Skip to content
This repository has been archived by the owner on Apr 7, 2024. It is now read-only.

feat: remove dependency of docker-credentials-helper and support context #68

Merged
merged 22 commits into from
Jun 8, 2023
Merged

feat: remove dependency of docker-credentials-helper and support context #68

merged 22 commits into from
Jun 8, 2023

Conversation

wangxiaoxuan273
Copy link
Collaborator

@wangxiaoxuan273 wangxiaoxuan273 commented May 24, 2023

Resolves #67

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented May 31, 2023

Codecov Report

Merging #68 (ecb34fe) into main (97227b1) will decrease coverage by 0.45%.
The diff coverage is 66.66%.

❗ Current head ecb34fe differs from pull request most recent head 5e36dfc. Consider uploading reports for the commit 5e36dfc to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main      #68      +/-   ##
==========================================
- Coverage   81.13%   80.68%   -0.45%     
==========================================
  Files           6        6              
  Lines         371      378       +7     
==========================================
+ Hits          301      305       +4     
- Misses         48       49       +1     
- Partials       22       24       +2     
Impacted Files Coverage Δ
native_store.go 73.91% <66.66%> (-3.02%) ⬇️

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
main/main.go Fixed Show fixed Hide fixed
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
@wangxiaoxuan273 wangxiaoxuan273 marked this pull request as ready for review June 5, 2023 13:00
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
native_store.go Outdated Show resolved Hide resolved
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
native_store.go Outdated Show resolved Hide resolved
native_store.go Show resolved Hide resolved
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
internal/executer/executer.go Show resolved Hide resolved
}

// NewExecuter returns a new Executer instance.
func NewExecuter(name string) Executer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to be used as executer.New().

Suggested change
func NewExecuter(name string) Executer {
func New(name string) Executer {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the function

native_store.go Outdated
Comment on lines 37 to 39
ServerURL string
Username string
Secret string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to explicitly declare the json field name. For example:

ServerURL string `json:"ServerURL"`

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the json field name.

Comment on lines +34 to +35
// dockerCredentials mimics how docker credential helper binaries store
// credential information.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the reference link.

native_store.go Outdated
// nativeStore implements a credentials store using native keychain to keep
// credentials secure.
type nativeStore struct {
programFunc client.ProgramFunc
executer.Executer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to give this component name like

Suggested change
executer.Executer
exec executer.Executer

Otherwise, all public method of executer.Executer will be exposed to the nativeStore. In other words, some one can do

store := NewNativeStore("foobar")
exec := store.(executer.Executer)
exec.Execute(ctx, "hello", "get")

which should not be allowed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added back the variable name.

native_store.go Outdated
Comment on lines 70 to 72
dockerCred := &dockerCredentials{
ServerURL: serverAddress,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning to pre-fill the content as Decode will clean it anyway.

Consider the following code

var dockerCred dockerCredentials
if err := json.Unmarshal(out, &dockerCred); err != nil {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with the code above.

native_store.go Outdated
Comment on lines 97 to 101
buffer := new(bytes.Buffer)
if err := json.NewEncoder(buffer).Encode(dockerCred); err != nil {
return err
}
_, err := ns.Execute(ctx, buffer, "store")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using json.Marshal() and bytes.NewReader().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated accordingly.

@shizhMSFT
Copy link
Contributor

@wangxiaoxuan273 The code coverage drops. You may want to have a net gain on it.

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>

// NewExecuter returns a new Executer instance.
func NewExecuter(name string) Executer {
return &executable{
Copy link
Member

@Wwwsylvia Wwwsylvia Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A question: Do weed need to check if the executable can be found? Like using exec.LookPath?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need more discussion on that? This is worth a future "feat" PR. I'll leave it as it is for this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good idea and is necessary for detecting desktop.exe. However, we can leave it in the next PR.

@wangxiaoxuan273
Copy link
Collaborator Author

wangxiaoxuan273 commented Jun 8, 2023

@wangxiaoxuan273 The code coverage drops. You may want to have a net gain on it.

I looked at the CodeDev report, currently all parts of native_store.go are covered, except the error handling parts of json.Marshall/Unmarshall and Execute. I don't think unit tests for these functions are necessary, just to increase the code coverage.

internal/executer/executer.go Outdated Show resolved Hide resolved

// NewExecuter returns a new Executer instance.
func NewExecuter(name string) Executer {
return &executable{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good idea and is necessary for detecting desktop.exe. However, we can leave it in the next PR.

native_store.go Outdated Show resolved Hide resolved
@shizhMSFT
Copy link
Contributor

shizhMSFT commented Jun 8, 2023

I don't think unit tests for these functions are necessary, just to increase the code coverage.

@wangxiaoxuan273 It is necessary. Unit tests are not just for positive paths. Negative paths are equivalently important.

Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@Wwwsylvia Wwwsylvia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@Wwwsylvia Wwwsylvia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Wwwsylvia Wwwsylvia merged commit ab5d0bd into oras-project:main Jun 8, 2023
shizhMSFT pushed a commit that referenced this pull request Jun 8, 2023
Fixing the error of PR #68

---------

Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
@wangxiaoxuan273 wangxiaoxuan273 changed the title feat: add package client, the Program type and its related operations feat: remove dependency of docker-credentials-helper and support context Jun 20, 2023
@wangxiaoxuan273 wangxiaoxuan273 deleted the infra branch June 20, 2023 06:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Context Support for Native Store
5 participants